﻿using System.Drawing;
using System.Drawing.Imaging;
using System.Windows;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;


namespace LoD.Tools.TilesetMaker {
    public partial class MainWindow {
        public TileSet TSet;

        public MainWindow() {
            this.InitializeComponent();
            this.TSet = new TileSet();
            this.TSet.Type = TileSet.TilesetType.Mobile;
            DataContext = this.TSet;
        }

        private void CreateTilesetButtonClick(object sender, RoutedEventArgs e) {
            var imageFolder = new FolderBrowserDialog {
                ShowNewFolderButton = false,
                Description = "Select the folder containing the image files you want to add to the current tileset."
            };
            if (imageFolder.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            Bitmap tileset = this.TSet.Create(imageFolder.SelectedPath);
            var dialog = new SaveFileDialog {
                DefaultExt = ".png",
                Filter = "PNG Images|*.png|All Files|*.*",
                FilterIndex = 1
            };
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) tileset.Save(dialog.FileName, ImageFormat.Png);
            else MessageBox.Show("Saving tileset canceled!");
        }
    }
}